

inherit "obj/object.c"

int main(var me,string arg){

    if( !arg ){
        tellObject(me,"你要往哪儿走？");
        return;
    }

    if( !environment(me) ){
        tellObject(me,"你现在的情况还是赶紧联系巫师吧！");
        return 0;
    }
    object env = environment(me);
    //出口数据
    map exits;
    string exitIdent;
    object destExit;

    if( !mapp( exits = env.query("exits") )  ){
        tellObject(me,"这儿的出口有些问题！！");
        return 0;
    }

    if( !(exitIdent = exits[arg])  ){

        tellObject(me,"这个方向没有出口！");
        return 0;
    }

    tellObject(me,"目标出口地址是"+exitIdent);
     if( strsrch(exitIdent,"#") < 0 ){//没有转换成对象的地址
//       varDump(env.query("exits"),exitIdent);
        destExit = new(exitIdent);
        //把目标房间的所有出口遍历一遍，找出和环境一样的，再替换成环境的
        var destExitPaths = destExit.query("exits");
        string path = baseName(env);
        foreach(k  in keys(destExitPaths)){
             if( strsrch(destExitPaths[k],path) >= 0 &&  strsrch(destExitPaths[k],"#") < 0 ){
//               tellObject(me,"给目标房间赋值成功");
                destExitPaths[k] = fileName(env);
             }
        }
        exits[arg] = fileName(destExit);
//        tellObject(me,"看看能找到多少次!-->"+exits[arg]+toJsonStr(env.query("exits")));
     }else{
        if(  !objectp(destExit = findObject(exitIdent))  ){
           tellObject(me,"这个地方过不去！");
           return 0;
        }
     }







    println( "找到的环境是" + baseName(destExit) );

    me.move(destExit);
    tellObject(me,"你来到了 "+destExit.query("short")+" 。"+baseName(destExit));
}

